package First;
import java.util.Scanner;

public class maxSubArray {
    public static int max(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }

            int max = nums[0]; // 迄今为止的最大子数组和
            int currentMax = nums[0]; // 当前子数组的和

            for (int i = 1; i < nums.length; i++) {
                currentMax = Math.max(nums[i], currentMax + nums[i]);
                max = Math.max(max, currentMax);
            }

            return max;
        }

        public static void main (String[] agrs){
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[] sum = new int[n];
            for (int i = 0; i < n; i++) {
                sum[i] = sc.nextInt();
            }
            System.out.println(max(sum));
        }
    }

